#include "readColor.h"
#include "colorData.h"
#include <stdio.h>
#include "baseVector.h"

void drawColorBuffer (colorData* buffer,int size)
{
  /* printf("drawing color buffer, %d colors\n",size); */
  int i=0;
  glBegin(GL_POINTS);
  for (i=0;i<size;i++)
    {

      glVertex3i(buffer[i].r,buffer[i].g,buffer[i].b);
    }
  glEnd();
}

void chgColor (colorData* buf,int nbColor,unsigned char* img,int width,int height, colorData oldCol,colorData newCol)
{
  if (isColorInTab(buf,newCol,nbColor)>=0)
    {
      printf("COLOR COLLISION\n");
    }

  /* the old color is at this subscript in the colordata buffer */
  int subscript=isColorInTab(buf,oldCol,nbColor);
  /* we alter its value */
  buf[subscript].r=newCol.r;
  buf[subscript].g=newCol.g;
  buf[subscript].b=newCol.b;

  /* we alter all value of old color in our image */
  int i=0;
  for (i=0;i<width*height;i+=3)
    {
      colorData col;
      col.r=img[i + 0];
      col.g=img[i + 1];
      col.b=img[i + 2];
      if (isColorEqual(oldCol,col))
	{
	  img[i + 0]=newCol.r;
	  img[i + 1]=newCol.g;
	  img[i + 2]=newCol.b;
	}
    }

}
